use strict;
use warnings;

package JasPerl::PageContext::HashSupport;

sub new_hash {
    my %hash;
    tie %hash, shift, @_;
    return \%hash;
}

sub TIEHASH {
    my $class = shift;
    return $class->new(@_);
}

sub FETCH {
    return $_[0]->get($_[1]);
}

sub STORE {
    return $_[0]->put($_[1], $_[2]);
}

sub DELETE {
    return $_[0]->remove($_[1]);
}

sub CLEAR {
    return $_[0]->clear();
}

sub EXISTS {
    return defined $_[0]->get($_[1]);
}

sub FIRSTKEY {
    $_[0]->{_} = $_[0]->keys();
    return $_[0]->NEXTKEY;
}

sub NEXTKEY {
    return unless $_[0]->{_}->has_next();
    return $_[0]->{_}->next();
}

sub SCALAR {
    return $_[0]->keys()->has_next();
}

1;
